package Demo5;

import java.util.Scanner;

class List {
	String name;
	int A_need;
	int B_need;
	int C_need;
	int A_assigned;
	int B_assigned;
	int C_assigned;
	boolean flag=false;

	public List(String name, int a_need, int b_need, int c_need, int a_assigned, int b_assigned, int c_assigned) {
		this.name = name;
		A_need = a_need;
		B_need = b_need;
		C_need = c_need;
		A_assigned = a_assigned;
		B_assigned = b_assigned;
		C_assigned = c_assigned;
	}
}

public class Data {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		List[] list = new List[4];
		int data[] = new int[3];
		//输入A、B、C各自的资源总量
		for (int i = 0; i < data.length; i++) {
			data[i] = s.nextInt();
		}
		//
		for (int i = 0; i < list.length; i++) {
			String name = s.next();
			int A_need = s.nextInt();
			int B_need = s.nextInt();
			int C_need = s.nextInt();
			int A_assigned = s.nextInt();
			int B_assigned = s.nextInt();
			int C_assigned = s.nextInt();
			list[i] = new List(name, A_need, B_need, C_need, A_assigned, B_assigned, C_assigned);
		}
		int[] array = new int[3];
		int[] count = new int[4];
		for (int i = 0; i < 4; i++) {
			count[0] += list[i].A_assigned;
			count[1] += list[i].B_assigned;
			count[2] += list[i].C_assigned;
		}
		//array数组存放当前仅剩的资源
		for (int i = 0; i < 3; i++) {
			array[i] = data[i] - count[i];
		}
		for (int i = 0; i < 4; i++) {
			list[i].A_assigned = list[i].A_need - list[i].A_assigned;
			list[i].B_assigned = list[i].B_need - list[i].B_assigned;
			list[i].C_assigned = list[i].C_need - list[i].C_assigned;
		}
		int i = 0,k=0;
		int len = list.length;
		boolean sign=true;
		String []name=new String[4];
		while (len > 0&&sign) {
			sign=false;
				for (int j = 0; j < list.length; j++) {
					//如果里面的flag为true表示已经执行完毕
					//那么以下都不用执行，直接continue到j++;
					if (list[j].flag) {
						continue;
					}
					if (array[i] >= list[j].A_assigned && array[i + 1] >= list[j].B_assigned && array[i + 2] >= list[j].C_assigned) {
						array[i] += (list[j].A_need - list[j].A_assigned);
						array[i + 1] += (list[j].B_need - list[j].B_assigned);
						array[i + 2] += (list[j].C_need - list[j].C_assigned);
						//true表示已经执行完毕的
						name[k++]=list[j].name;
						list[j].flag = true;
						sign=true;
						len--;
					}
				}
		}
		if(sign) {
			for (String value : name) {
				System.out.print(value + " ");
			}
		}else{
			System.out.println("false");
		}
	}

}

